package com.buba.system.controller;

import com.buba.system.pojo.SystemMenu;
import com.buba.system.pojo.SystemUser;
import com.buba.system.service.MenuService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/MenuController")
public class MenuController {
    private MenuService menuService;

//    @RequiresRoles("超级管理员") //用来判断角色权限
    @RequestMapping("selMenu")
    public Map<String,Object> selMenu(){
        Map<String,Object> map=new HashMap<>();
        //获取父级菜单信息
        List<SystemMenu> menuList = menuService.selMenu();
        //根据父级id获取子级菜单
        for (SystemMenu menu:menuList) {
            List<SystemMenu> childList = menuService.selMenuById(menu.getMenuId());
            menu.setSubMenu(childList);
        }
        map.put("menuList",menuList);
        return map;
    }


    @Autowired
    @Qualifier("menuServiceImpl")
    public void setMenuService(MenuService menuService) {
        this.menuService = menuService;
    }
}
